﻿Imports tiendaRegalos
Public Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btnIngresar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnIngresar.Click
        Try
            Dim negocio As New UsuarioNegocio
            Dim modelo = negocio.login(Me.txtUsuario.Text, Me.txtClave.Text)

            Dim listaRoles = modelo.usuarios

            Dim url As String = ""

            For Each x As Rol In listaRoles

                ' Si es Administrador
                If Constantes.ROL_ADMIN = x.idRol Then
                    url = "~/inicio.aspx"
                End If

                ' Si es Vendedor
                If Constantes.ROL_VENTAS = x.idRol Then
                    url = "~/Invitados.aspx"
                End If

            Next

            Session.Add("USUARIO_ACTUAL", modelo)

            Response.Redirect(url, False)

        Catch ex As Exception
            Response.Write(ex.Message)
        End Try

    End sub
End Class